import urllib.request
import urllib.parse


if __name__ == '__main__':
    url = 'https://so.csdn.net/so/search/s.do'
    params = {'q': '大江狗', }

    header = {
        'User-Agent': 'Opera/9.80 (Windows NT 6.1; U; en) Presto/2.8.131 Version/11.11',
    }

    # 使用parse方法对参数进行URL编码
    encoded_params = urllib.parse.urlencode(params)

    # 拼装后的request地址是https://so.csdn.net/so/search/s.do?q=大江狗
    request_url = urllib.request.Request(url + '?' + encoded_params, headers=header)
    response = urllib.request.urlopen(request_url)

    print(response.read().decode('utf-8'))
